const os = require('os');
const fs = require('fs');
const path = require('path');

const getIP = () => {
    const networkInterfaces = os.networkInterfaces();
    const key = Object.keys(networkInterfaces)[0];
    const target = networkInterfaces[key].filter(item => item.family === 'IPv4')[0];
    return target.address
}

const resolve = (dir = './') => {
    return path.resolve(__dirname, '..', dir);
}

const getEntries = (dir = 'src/pages') => {
    const pagesDir = resolve(dir);
    const HTMLFiles = fs.readdirSync(pagesDir).filter(item => /\.html$/.test(item));
    let entries = {};
    HTMLFiles.forEach(item => {
        const name = item.replace(/\.html$/, '');
        const jsPath = resolve(`src/js/${name}.js`);
        entries[name] = jsPath;
    });
    return entries;
}



module.exports = {
    getIP,
    resolve,
    getEntries
}